function Header($){
	var Menus = {
		1:  [
			{
				url:"/brandStory.htm",title:"品牌故事",tg:"1"
			},
			{
				url:"/activity.htm",title:"活动报道",tg:"2"
			},
			{
				url:"/about.htm",title:"联系我们",tg:"3"
			}
		],
		2:  [
			{
				url:"/prodCategory.htm",title:"按产品类别查询",tg:"1"
			},
			{
				url:"http://catalogue.acdelco.com.cn/ProdSearchByCarTypePC/Index",title:"配件线上目录",tg:"2",withsub:"1",
				submenus:[
					{url:"http://catalogue.acdelco.com.cn/ProdSearchByVinPC/Index",title:"按VIN码查询",tg:"1"},
					{url:"http://catalogue.acdelco.com.cn/ProdSearchByCarTypePC/Index",title:"按车型查询",tg:"2"},
					{url:"http://catalogue.acdelco.com.cn/ProdSearchByPrdArrayPC/Index",title:"按产品组查询",tg:"3"},
					{url:"http://catalogue.acdelco.com.cn/ProdSearchByPartPC/Index",title:"按零件号查询",tg:"4"}
				]
			},
			{
				url:"/securityLabel.htm",title:"防伪标签查询",tg:"3"
			}
		],
		3:  [
			{
				url:"/carSystem.htm",title:"汽车系统",tg:"1"
			},
			{
				url:"/fixGeneral.htm",title:"维修常识",tg:"2"
			},
			{
				url:"/storeShop.htm",title:"快修店网络查询",tg:"3"
			}
		],
		6:  [
			{
				url:"https://mall.jd.com/index-749060.html",title:"京东车工坊",tg:"1"
			},
			{
				url:"https://acdelco.tmall.com",title:"德科天猫旗舰店",tg:"2"
			}
		],
		7:  [
			{
				url:"/",title:"中国",tg:"1",en:"CHINA"
			},
			{
				url:"https://www.acdelco.com",title:"美国",tg:"2",en:"AMERICA"
			}
		]
	}
	return {
		init:function(headerPos){
			var _this = this;
			_this.headerPos = headerPos;
			_this.setMenu();
			_this.bindEvents();
		},
		setMenu:function(){
			var _this = this;
			$(".wrapper-head-menu").find("li").removeClass("active");
			$(".wrapper-head-menu").find("li[tg='" + _this.headerPos.menu + "']").addClass("active");
		},
		bindEvents:function(){
			var _this = this;
			$(".wrapper-head-menu").find("li").hover(function(){
				$(".wrapper-head-menu").find("li").removeClass("active");
				$(this).addClass("hover");
				_this.withSub = null;
				$("#submenu2").html("");
				var withsub = $(this).attr("withsub");
				if(withsub == "1"){
					$(".sub-menus-con").removeClass("loc");
					$(".sub-menus-con").find(".sub-menus").removeClass("loc").removeClass("f-right-imp");
					var offset = $(this).offset();
					var tg = $(this).attr("tg");
					if(tg == "7"){
						_this.setLocale(tg);
						_this.animateBlockDisp();
						return;
					}
					_this.setFirstLevel($(this).attr("tg"));
					$(".sub-menus-con").css({"margin-left":offset.left});
					_this.animateBlockDisp();

				}else{
					_this.animateBlockHide();
				}
			},function(){
				$(".wrapper-head-menu").find("li").removeClass("hover");
			});
			$(".wrapper-head-menu").on("mouseleave",function(){
				if(!$(".warpper-sub-menu").hasClass("active")){
					_this.setMenu();
				}
			})
			$(".warpper-sub-menu").on("mouseleave",function(){
				_this.animateBlockHide();
				_this.setMenu();
			});
			// 点击京东、天猫
			$("#submenu1").on('click','li a',function(){
				if($(this).parent().attr('partg') == 6 && $(this).parent().attr('tg') == 1){
					_this.getHits(1);
				}else if($(this).parent().attr('partg') == 6 && $(this).parent().attr('tg') == 2){
					_this.getHits(2);
				}
			});
			// 点击在线购买
			$(".wrapper-head-menu").on('click','li a',function(){
				if($(this).parent().attr('tg') == 6){
					_this.getHits(1);
				}
			})
		},
		animateBlockDisp:function(){
			var _this = this;
			$(".warpper-sub-menu").addClass("active");
			$(".warpper-sub-menu").stop();
			$(".warpper-sub-menu").animate({top:"6.8em"},400);
		},
		animateBlockHide:function(){
			var _this = this;
			$(".warpper-sub-menu").removeClass("active");
			$(".warpper-sub-menu").stop();
			$(".warpper-sub-menu").animate({top:"-20em"},400);
		},
		setLocale:function(tg){
			var _this = this;
			$(".sub-menus-con").css({"margin-left":"0"});
			$(".sub-menus-con").addClass("loc");
			$(".sub-menus-con").find(".sub-menus").addClass("loc").addClass("f-right-imp");
			$(".sub-menus-con").find(".sub-menus").addClass("loc");
			var subMenus = Menus[tg];
			var html = "",html1="";
			html += "<ul>";
			html1 += "<ul>";
			$(subMenus).each(function(idx){

				if(idx<4){
					html += '<li partg="' + tg + '" tg="' + this.tg + '"> ';
					html += '	<a href="' + this.url + '"><span class="f-left">' + this.en + '</span><span class="f-right">' +  this.title + '</span><i class="sub"></i></a> ' ;
					html += '	<div class="line"><div class="line-y"></div></div> ';
					html += '</li> ';
				}else{
					html1 += '<li partg="' + tg + '" tg="' + this.tg + '"> ';
					html1 += '	<a href="' + this.url + '"><span class="f-left">' + this.en + '</span><span class="f-right">' +  this.title + '</span><i class="sub"></i></a> ' ;
					html1 += '	<div class="line"><div class="line-y"></div></div> ';
					html1 += '</li> ';
				}
			});
			html += "</ul>";
			html1 += "</ul>";
			$("#submenu1").html(html);
			$("#submenu2").html(html1);
			$(".sub-menus").find("li").hover(function(){
				$(this).addClass("hover");
				$(this).find(".line-y").stop();
				$(this).find(".line-y").animate({
					width:"100%"
				},400);
			},function(){
				$(this).removeClass("hover");
				//
				$(this).find(".line-y").stop();
				$(this).find(".line-y").animate({
					width:"0"
				},400);
			});
		},
		setFirstLevel:function(tg){
			var _this = this;
			var subMenus = Menus[tg];
			var html = "";
			html += "<ul>";
			$(subMenus).each(function(){
				html += '<li partg="' + tg + '" tg="' + this.tg + '" withsub="' + (this.withsub == "1"?"1":"0") + '"> ';
				html += '	<a href="' + this.url + '">' + this.title + '<i class="sub"></i></a> ' ;
				html += '	<div class="line"><div class="line-y"></div></div> ';
				html += '</li> ';
			});
			html += "</ul>";
			$("#submenu1").html(html);
			$("#submenu1").find("li").hover(function(){
				if(_this.withSub && _this.withSub != $(this).attr("tg")){
					$("#submenu1").find("li").removeClass("hover");
					$("#submenu1").find("li[tg=" + _this.withSub + "]").find(".line-y").stop();
					$("#submenu1").find("li[tg=" + _this.withSub + "]").find(".line-y").animate({width:"0"},400);
					$("#submenu2").html("");
				}
				$(this).addClass("hover");
				$(this).find(".line-y").stop();
				$(this).find(".line-y").animate({
					width:"100%"
				},400);

				if($(this).attr("withsub") == "1"){
					_this.withSub = $(this).attr("tg");
					_this.setSecLevel($(this).attr("partg"),$(this).attr("tg"));
				}

			},function(){
				if($(this).attr("withsub") == "1"){
					return;
				}
				$(this).removeClass("hover");
				$(this).find(".line-y").stop();
				$(this).find(".line-y").animate({
					width:"0"
				},400);

			});
		},
		setSecLevel:function(partg,tg){
			var _this = this;
			var subMenus = _this.getSecInfo(partg,tg);
			var subId = '"submenu' + partg +'_' + tg + '"';
			var html = "";
			//html += '<div class="sub-menus" id=' + subId + '></div>';
			html += "<ul>";
			$(subMenus).each(function(){
				html += '<li partg="' + tg + '" > ';
				html += '	<a href="' + this.url + '">' + this.title  + '<i class="sub"></i></a> ' ;
				html += '	<div class="line"><div class="line-y"></div></div> ';
				html += '</li> ';
			});
			html += "</ul>";
			$("#submenu2").html(html);
			$("#submenu2").hover(function(){
				$(this).addClass("in");
			},function(){
				$(this).removeClass("in");
			});
			$("#submenu2").find("li").hover(function(){
				$(this).find(".line-y").stop();
				$(this).find(".line-y").animate({
					width:"100%"
				},400);
				$(this).addClass("hover");
			},function(){
				$(this).removeClass("hover");
				$(this).find(".line-y").stop();
				$(this).find(".line-y").animate({
					width:"0"
				},400);
			});
		},
		getSecInfo:function(partg,tg){
			var res;
			$(Menus[partg]).each(function(){
				if(this.tg == tg){
					res = this.submenus;
				}
			});
			return res ||[];
		},
		getHits: function(tg){
			$.ajax({
				url:"https://www.acdelco.com.cn/clickstatistics/addCount.json",
				// url:"http://192.168.0.110:8080/clickstatistics/addCount.json",
				data:{
					playType: 1,
					urlType: tg
				},
				type:'get',
				success:function(res){
					console.log(tg);
				}
			})
		}
	}
}

if("function"==typeof define && define.amd && define){
	define(['jquery'],function($){
		return Header($);
	});
}